package name.mrzc.licensing.dbutils;

import java.sql.SQLException;
import java.util.List;

import javax.sql.DataSource;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import name.mrzc.licensing.db.ILicenseDB;
import name.mrzc.licensing.model.License;

@Component
public class LicenseDbutils implements ILicenseDB {

	@Autowired
	DataSource dataSource;

	public List<License> findByOrganizationId(String organizationId) {

		QueryRunner runner = new QueryRunner(dataSource);
		List<License> list = null;
		try {
			list = runner.query(
					"select license_id licenseId,organization_id organizationId,product_name productName,license_type licenseType,"
							+ "license_max licenseMax,license_allocated licenseAllocated,comment as comment from licenses where organization_id = ?",
					new BeanListHandler<License>(License.class), organizationId);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public License findByOrganizationIdAndLicenseId(String organizationId, String licenseId) {
		// TODO Auto-generated method stub
		return null;
	}

}
